<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/basejsp.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<script type="text/javascript">
	/*验证验证码是否正确  */
		/* $(function() {
			$("#next").click(function() {
			var email = $("input[name='email']").val();
			var yanzheng=$("input[name='yanzheng']").val()
			var yzm='${yz}';
				if(yzm==yanzheng){
					$("form").attr("action","user.action?methodName=doUpdatePassword").submit();  
				}else{
					alert("验证码错误，请重新输入！");
				}
				
			});
		}); */
	
	
	</script>

</head>



<body style="background: url('img/0407.jpg') no-repeat;  background-size:1278px 670px">
	<script type="text/javascript">
	<% 
	String code=(String)session.getAttribute("yz"); %>
		$(function() {
			$("#next").click(function() {
			/* var email = $("input[name='email']").val(); */
			var yanzheng=$("input[name='yanzheng']").val()
			alert("code+==="+"<%=code %>");
			/* $.post("user.action?methodName=yzEmail","email="+email,function(data){ */
				if(yanzheng=="<%=code %>"){
					$("form").attr("action","user.action?methodName=doUpdatePassword").submit();  
					<%-- <%session.removeAttribute("yz"); %> --%>
				}else{
					alert("验证码错误，请重新输入！");
				}
				
			});
		});
	
	
	
	</script>
	
	
	
	
	
	<form action="" method="post" >
	<br /><br /><h2 style="color: white;">找回密码</h2>
		<table align="center" >
			<tr>
				<th align="left" style="color: white;">用户名：</th>
				<td align="left" >
					<input type="text" placeholder="请输入注册的用户名"  name="userName" /><b><span id="resultUsername" style="color: red;"></span></b>
					<input type="hidden" name="userid" value="userName"/>
				</td>
			</tr>
			
			<tr>
				<th align="left" style="color: white;" >密码：</th>
				<td align="left">
					<input type="password" placeholder="请输入新密码" name="password" value="${users.userId }"/><b><span id="resultPassword" style="color: red;"></span></b>
				</td>
			</tr>
			<tr>
				<th align="left" style="color: white;" >确认密码：</th>
				<td align="left">
					<input type="password" placeholder="请再次输入新密码" name="againPassword" /><b><span id="resultAgainPassword" style="color: red;"></span></b>
				</td>
			</tr>
			
			
			<tr>
				<th align="left" style="color: white;">邮箱：</th>
				<td align="left">
					<input type="text" placeholder="请输入注册的邮箱" name="email"/><b><span id="resultEmail" style="color: red;"></span></b>
				</td>
			</tr>
			 <tr>
				<th align="left" style="color: white;">验证码：</th>
				<td align="left">
					<input type="text" style="height: 25px;" placeholder="请输入验证码" name="yanzheng" />
					
					<input type="button" value="发送验证码" onclick="dianji()" />
					
				</td>
			</tr>
			 
		</table>
		<br />
		<div style="margin-left: 20px" >
			<input type="button" value="重置密码" style="color: black;margin-right: 40px" id="next"/>
			<input type="button" value="返回" onclick="window.location='doLogin.action?methodName=toLogin'" style="color: black;"/>
		</div>
	</form>
	
	
</body>

	
	<script type="text/javascript">
	
	/*判断邮箱格式是否正确  */
		 $(function() {
			 
			$("form").click(function(){
				
				var userName = $("input[name='userName']").val();
				var Email = $("input[name='email']").val();
				var regEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
				var yanzheng=$("input[name='yanzheng']").val();
				var code="${yz}"; 
				
				if(userName == "") {
					$("#resultUsername").text("请输入用户名！");
					return false;
				}else if(userName.length<5||userName.length>20) {
					$("#resultUsername").text("用户名长度必须是5至20之间！");
					return ;
				}
				
				/*验证用户名是否已存在  */
				$("input[name='userName']").blur(function() {
					$("#resultUsername").text("");
					var uname=$(this).val();
					$.ajax({
						type:"post",
						url:"user.action?methodName=ajaxResetPassword",
						data:{"userName":uname},
						success:function(resultData){
							if(!resultData) {
								$("#resultUsername").text("该用户名不存在，请重新输入！");
								return;
							}else{
								$("#resultUsername").text("√");
							}
						}
					});
				});
				
				
				if(Email == "") {
					$("#resultEmail").text("请输入的邮箱!");
                    return false;
				}else if (!regEmail.test(Email)) {
					$("#resultEmail").text("对不起，您输入的邮箱格式不正确!");
                     return false;
				}
				
				/*验证邮箱是否已存在  */
				$("input[name='email']").blur(function() {
					$("#resultEmail").text("");
					var mail=$("input[name='email']").val();
					$.ajax({
						type:"post",
						url:"user.action?methodName=ajaxResetPassword",
						data:{"email":mail},
						success:function(resultData){
							if(!resultData) {
								$("#resultEmail").text("该邮箱不存在，请重新输入！");
								return;
							}else{
								$("#resultEmail").text("√");
							}
						}
					});
				});
			}); 
		 });
	
		
	</script>
	<!--发送邮箱验证码  -->
	<script type="text/javascript">
		function dianji(){
			var email = $("input[name='email']").val();
			
			$.post("user.action?methodName=yzEmail","email="+email,function(data){
				if(data!="cuowu"){
					alert("验证码已发送，请查收！");
				}else{
					alert("邮箱发送失败！请稍后重试！");
				}
			});
		}
		
	
	
	</script>
	<script type="text/javascript">
		$(function() {
			$("form").click(function() {
				var password = $("input[name='password']").val();
				var againPassword = $("input[name='againPassword']").val();

				if(password == "") {
					$("#resultPassword").text("请输入密码！");
					return false;
				}
				if(password.length<4||password.length>20) {
					$("#resultPassword").text("密码长度必须是4至20之间！");
					return false;
				}else{
					$("#resultPassword").text("√");
				}
				
				
				
				if(againPassword == "") {
					$("#resultAgainPassword").text("确认密码不能为空！");
					return false;
				}else if(againPassword.length<4||againPassword.length>20) {
					$("#resultAgainPassword").text("确认密码长度必须是4至20之间！");
					return false;
				}else if(againPassword != password) {
					$("#resultAgainPassword").text("两次密码不一致！");
					return false;
				}else{
					$("#resultAgainPassword").text("√");
				}
				
			});
		});
	
	</script> 
	
	
	

</html>